package com.chen.springboot.service.Impl.uniapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.springboot.dto.uniapp.Goods;
import com.chen.springboot.dto.uniapp.PageResult;
import com.chen.springboot.mapper.uniapp.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    public PageResult findPages(int pageNum, int pageSize, String keyword) {
        // 创建分页对象
        Page<Goods> goodsPage = new Page<>(pageNum, pageSize);
        // 执行查询
        goodsMapper.selectPage(goodsPage, keyword);
        // 将分页数据封装成 PageResult
        PageResult pageResult = new PageResult();
        pageResult.setCounts(goodsPage.getTotal());
        pageResult.setPageSize(goodsPage.getSize());
        pageResult.setPages(goodsPage.getPages());
        pageResult.setPage(goodsPage.getCurrent());
        pageResult.setItems(goodsPage.getRecords());
        //检查是否有更多数据
        boolean hasMore=goodsPage.hasNext();
        pageResult.setHasMore(hasMore);
        return pageResult;
    }
}
